#include <stdio.h>
#include<stdlib.h>

typedef struct node *Students;
struct node {
    int identifier;
    int pub;
};

int main() {
    int n;
    int m;
    scanf("%d%d",&n,&m);
    int Students[30001];
    for(int i=0; i<n; i++) {
        Students[i+1]=-1;
    }
    int Pubs[1001];
    for(int i=0; i<m; i++) {
        Pubs[i]=i;
    }
    for(int i=0; i<m; i++) {
        int members;
        int flag=i;
        scanf("%d",&members);
        while(members--) {
            int Eachmember;
            scanf("%d",&Eachmember);
            if(Students[Eachmember]==-1) {
                Students[Eachmember]=flag;
            } 
			else { 
                int parents=Pubs[i]<Pubs[Students[Eachmember]]?Pubs[i]:Pubs[Students[Eachmember]];
                Pubs[i]=parents;
                Pubs[Students[Eachmember]]=parents;
                flag=parents;
            }
        }
    }
	for(int i=0;i<n;i++){
   	 Students[i]=Pubs[Students[i]];
	}
	int MostFriends=0;
	for(int i=0;i<m;i++){
		if(Pubs[i]!=i)continue;
		int Friends=0;
 		for(int j=1;j<=n;j++){
  	      if(Students[j]==i)Friends++;
		}
    if(Friends>MostFriends)MostFriends=Friends;
	}
	printf("%d",MostFriends);
    return 0;
}


//Students Creat(int n){
//  Students temp=(Students)malloc(sizeof(struct node)*n);
//  for(int i=0;i<n;i++){
//      temp[i].identifier=i;
//
//  }
//}
